﻿<html>
<head>
	<title>快速排序算法过程标记</title>
</head>
<body>
	<script language="JavaScript"> 
	function qSort(list){
		if(list.length <= 1){
			return list;
		}
		var lesser = [];
		var greater = [];
		var pivot = list[0];
		for(var i = 1; i < list.length; i++){
			console.log("基准值："+pivot+" 当前元素："+list[i]);
			if(list[i] < pivot){
				console.log("移动"+list[i]+"到左边");
				lesser.push(list[i]);
			}else{
			console.log("移动"+list[i]+"到右边");
				greater.push(list[i]);
			}
		}
		return qSort(lesser).concat(pivot,qSort(greater));
	}
	var arr=[];
	for(var i = 0; i < 10; ++i){
		arr[i] = Math.floor(Math.random()*100+1);
	}
	console.log("原始数组："+arr.toString());
	var array = qSort(arr);
	console.log("最终数组："+array.toString());
</script>
</body>
</html>
